package com.lijianlove.keeplearning.dt;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lijianlove.keeplearning.strategy.UserStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

/**
 * @author lijian
 * @date 2019/4/28 上午11:54
 */
@DS("db_1")
@Slf4j
@Service
public class TransactionService {


    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserStrategy userStrategy;

    /**
     * 添加断点，跟踪事务机制
     */
    @Transactional
    public void testTransaction() {
        Random random = userStrategy.saveToDb1(jdbcTemplate);
//        int i = 1 / 0;
        userStrategy.saveToDb2(random, jdbcTemplate);
    }
}
